﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SD.Database.Classes;

namespace SDGUI
{
    public partial class FlightTime : UserControl
    {
        public FlightTime()
        {
            InitializeComponent();
        }

        private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            UpdateTime();
        }

        private void UpdateTime()
        {
            try
            {
                int fx = int.Parse(FromX.Text);
                int fy = int.Parse(FromY.Text);
                int fp = int.Parse(FromPlanet.Text);

                int tx = int.Parse(ToX.Text);
                int ty = int.Parse(ToY.Text);
                int tp = int.Parse(ToPlanet.Text);

                int en = int.Parse(Energy.Text);
                int sp = int.Parse(Speed.Text);
                int own = OwnPlanet.IsChecked.Value ? 1 : 0;
                TimeBlock.Text = "Calculated time: " + Equations.TravelTime(fx, fy, tx, ty, fp, tp, own, en, sp);
            }
            catch (Exception)
            {
                TimeBlock.Text = "Cannot Calculate time. ";
            }
        }

        private void CheckBox_Checked(object sender, RoutedEventArgs e)
        {
            UpdateTime();
        }
    }
}
